package com.ge.mythreed.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ge.mythreed.dto.req.PmPromotionTargetlistReqDto;
import com.ge.mythreed.dto.resp.PmPromotionTargetlistRespDto;
import com.ge.mythreed.entity.PmPromotionTargetlist;
import com.ge.mythreed.mapper.PmPromotionTargetlistMapper;
import com.ge.mythreed.service.PmPromotionTargetlistService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author sz
 * @description 针对表【pm_promotion_targetlist(营销对象信息)】的数据库操作Service实现
 * @createDate 2024-01-24 14:10:27
 */
@Service
public class PmPromotionTargetlistServiceImpl extends ServiceImpl<PmPromotionTargetlistMapper, PmPromotionTargetlist>
        implements PmPromotionTargetlistService {

    @Autowired
    private PmPromotionTargetlistMapper pmPromotionTargetlistMapper;

    /**
     * 查询分页列表
     *
     * @param pmPromotionTargetlistReqDto 请求参数对象
     * @return 分页对象
     */
    @Override
    public Page<PmPromotionTargetlistRespDto> queryPageList(PmPromotionTargetlistReqDto pmPromotionTargetlistReqDto) {
        Page<PmPromotionTargetlist> page = new Page<>(pmPromotionTargetlistReqDto.getPage(), pmPromotionTargetlistReqDto.getPageSize());
        QueryWrapper<PmPromotionTargetlist> pmPromotionTargetlistQueryWrapper = new QueryWrapper<>();
        pmPromotionTargetlistQueryWrapper.eq(StringUtils.isNotBlank(pmPromotionTargetlistReqDto.getPromotionCode()), "promotion_code", pmPromotionTargetlistReqDto.getPromotionCode());
        Page<PmPromotionTargetlist> pmPromotionTargetlistPage = this.page(page, pmPromotionTargetlistQueryWrapper);
        Page<PmPromotionTargetlistRespDto> resultPage = new Page<>();
        BeanUtils.copyProperties(pmPromotionTargetlistPage, resultPage);
        List<PmPromotionTargetlistRespDto> targetListRespDtoList = pmPromotionTargetlistPage.getRecords().stream().map(targetList -> {
            PmPromotionTargetlistRespDto targetlistRespDto = new PmPromotionTargetlistRespDto();
            BeanUtils.copyProperties(targetList, targetlistRespDto);
            return targetlistRespDto;
        }).collect(Collectors.toList());
        resultPage.setRecords(targetListRespDtoList);
        return resultPage;
    }
}




